define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'redeem/index' + location.search,
                    add_url: 'redeem/add',
                    // edit_url: 'redeem/edit',
                    // del_url: 'redeem/del',
                    multi_url: 'redeem/multi',
                    import_url: 'redeem/import',
                    table: 'redeem_code',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        { checkbox: true },
                        { field: 'id', title: __('Id') },
                        { field: 'code', title: __('Code'), operate: 'LIKE' },
                        { field: 'user.nickname', title: __('User.nickname'), operate: 'LIKE' },
                        { field: 'conversion_time', title: __('Conversion_time'), operate: 'RANGE', addclass: 'datetimerange', autocomplete: false, formatter: Table.api.formatter.datetime },
                        { field: 'address.contact', title: __('收货人'), operate: 'like' },
                        { field: 'address.telephone', title: __('收货电话'), operate: 'like' },
                        { field: 'address.province', title: __('省'), operate: 'like'},
                        { field: 'address.city', title: __('市'), operate: 'like'},
                        { field: 'address.area', title: __('区'), operate: 'like'},
                        { field: 'address.address', title: __('地址'), operate: 'like'},
                        { field: 'status', title: __('Status'), searchList: { "0": __('Status 0'), "1": __('Status 1') }, formatter: Table.api.formatter.status },
                        {
                            field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,
                            buttons: [
                                {
                                    name: 'select',
                                    title: '查看',
                                    text: '查看',
                                    extend: 'data-area=["90%","90%"]',
                                    classname: 'btn btn-primary btn-xs btn-view btn-dialog',
                                    url: 'send/log/index',//接口地址 控制器名/方法名
                                    visible: function (row) {//判断显示隐藏 只有状态为待审核时展示操作按钮
                                        if (row.status == '1') {
                                            return true;//显示
                                        } else {
                                            return false;//隐藏
                                        }
                                    },
                                },
                                {
                                    name: 'send',
                                    title: '发放',
                                    text: '发放',
                                    classname: 'btn btn-primary btn-xs btn-view btn-ajax',
                                    url: 'send/log/add',//接口地址 控制器名/方法名
                                    confirm:'是否确认发放？',
                                    visible: function (row) {//判断显示隐藏 只有状态为待审核时展示操作按钮
                                        if (row.status == '1') {
                                            return true;//显示
                                        } else {
                                            return false;//隐藏
                                        }
                                    },
                                },

                            ]
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
